package logic

import (
	"context"
	"medical/models/mysql"

	"medical/medicalrpc/internal/svc"
	"medical/medicalrpc/medicalrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopListLogic {
	return &ShopListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShopListLogic) ShopList(in *medicalrpc.ShopListRequest) (*medicalrpc.ShopListResponse, error) {
	// todo: add your logic here and delete this line

	var shop []mysql.Shop
	mysql.DB.Debug().Find(&shop)
	var shopList []*medicalrpc.ShopList
	for _, m := range shop {

		list := medicalrpc.ShopList{
			Id:     int64(m.ID),
			Num:    int64(m.Num),
			Name:   m.Name,
			Type:   m.Type,
			Status: m.Status,
		}
		shopList = append(shopList, &list)
	}
	return &medicalrpc.ShopListResponse{
		List: shopList,
	}, nil
}
